<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Show the photo gallery of the photo set.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.2
 * 
 * 0.2)  Uses the Gallery widget instead.
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_action.php';
require_once INSTALLDIR . '/lib/slh_util.php';

require_once INSTALLDIR . '/widgets/slh_gallery_photoset.php';

require_once INSTALLDIR . '/classes/PhotoSet.php';


class PhotosetAction extends Action
{
	/**
	 * The PhotoSet
	 */
	var $photoset = null;
	
	/**
	 * The photos in the gallery.
	 */
	var $photos = null;
	
	function title()
	{
		return '相册展示';
	}
	
	function prepare($args)
	{
		parent::prepare($args);
		
		// Parameter from 'get' url
		$photoset_id = $this->getTrimmedArg('gphotoset_id');
		
		if ( !is_numeric($photoset_id)) {
			return false;
		}
		
		// Get the photoset.
		$this->photoset = PhotoSet::staticGet('id', $photoset_id);
		if (empty($this->photoset)) {
			$this->clientError('找不到这个相册呃.');
		}
		
		// Get the photos.
		$this->photos = $this->photoset->getPhotos();
		if (empty($this->photos)) {
			$this->clientError('相册里面没有相片啊,亲.');
		}
		
		return true;
	}
	
	function handle($args)
	{
		parent::handle($args);

		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			;
		} else {
			$this->showPage();
		}
	}
	
	/**
	 * Overrideing the showInnerContent().
	 */
	function showInnerContent()
	{
		$this->element('h3', null, $this->photoset->title . ' @相册');
		
		$this->element('hr');
		
		$gallery = new PhotosetGallery($this->photos, $this);
		$gallery->show();
	}
	
	/**
	 * Add the ad-gallery stylesheet.
	 */
	function showStylesheets()
	{
		parent::showStylesheets();
		
		$this->cssLink('theme/base/css/jquery.ad-gallery.css', 'base', 'screen, projection, tv');
	}
	
	/**
	 * Add the ad-gallery scripts.
	 */
	function showScripts()
	{
		parent::showScripts();

		$this->script('ad-gallery/jquery.ad-gallery.min.js');
		$this->script('action/photoset.go.js');
	}
}

?>